package com.hgyc.mom.system.service.impl;

import com.hgyc.mom.common.context.FileServiceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hgyc.mom.system.mapper.SysAttachmentMapper;
import com.hgyc.mom.system.entity.SysAttachment;
import com.hgyc.mom.system.service.SysAttachmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 附件Service业务层处理
 *
 * @author fwj
 * @since 2025-04-27
 */
@Service
public class SysAttachmentServiceImpl extends ServiceImpl<SysAttachmentMapper, SysAttachment> implements SysAttachmentService
{
    @Autowired
    private FileServiceContext fileServiceContext;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeFiles(List<Long> ids) {
        for (Long id : ids) {
            SysAttachment sysAttachment = getById(id);
            fileServiceContext.deleteFile(sysAttachment.getFileUrl());
            removeById(id);
        }
    }
}
